//
//  FGTemplateMessageCell.m
//  lite
//
//  Created by feige on 2022/11/3.
//

#import "FGTemplateMessageCell.h"
#import "UIView+FGLayout.h"
#import "FGGoodsTemplateView.h"
#import "FGInterestTemplateView.h"
#import "FGActivityTemplateView.h"
#import "FGFromTemplateView.h"
#import "FGHelpTemplateView.h"
#import "FGSeatFromTemplateView.h"

#import "UIColor+FGChat.h"

@interface FGTemplateMessageCell()<FGSeatFromTemplateViewDelegate, FGTemplateViewDelegate>

@end

@implementation FGTemplateMessageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    }
    return self;
}

- (void)fillWithData:(FGTemplateMessageCellData *)data {
    [super fillWithData:data];
    self.templateData = data;
    
    [self.templateView removeFromSuperview];
    
    NSInteger type = [data.templateData[@"type"] integerValue];
    
    // 商品
    if (type == 3) {
        self.templateView = [FGGoodsTemplateView new];
    }
    // 兴趣
    else if (type == 1) {
        self.templateView = [FGInterestTemplateView new];
    }
    // 活动
    else if (type == 4) {
        self.templateView = [FGActivityTemplateView new];
    }
    // 表单
    else if (type == 5) {
        self.templateView = [FGSeatFromTemplateView new];
        ((FGSeatFromTemplateView *)self.templateView).delegate = self;
    }
    // 帮助
    else if (type == 2) {
        self.templateView = [FGHelpTemplateView new];
    }
    self.templateView.baseDelegate = self;
    
    self.templateView.backgroundColor = [UIColor whiteColor];
    self.templateView.layer.cornerRadius = 4;
    self.templateView.layer.shadowColor = [UIColor colorWithRed:202/255.0 green:215/255.0 blue:246/255.0 alpha:0.5000].CGColor;
    self.templateView.layer.shadowOffset = CGSizeMake(0,1);
    self.templateView.layer.shadowOpacity = 1;
    self.templateView.layer.shadowRadius = 6;
    [self.templateView fillData:self.templateData.templateData];
    [self.container addSubview:self.templateView];
}

- (void)layoutSubviews {
    [super layoutSubviews];
   
    self.templateView.frame = self.container.bounds;
}

#pragma mark - FGSeatFromTemplateViewDelegate

- (void)seatFromTemplateViewSubmitFrom:(NSArray *)fromArr
{
    if ([self.delegate respondsToSelector:@selector(fromSubmit:)]) {
        [self.delegate fromSubmit:fromArr];
    }
}

#pragma mark - FGTemplateViewDelegate

/**
 * 点击了模版消息上的Cell回调
 */
- (void)templateView:(FGBaseTemplateView *)templateView didSelectedCell:(NSDictionary *)templateDict
{
    if ([self.delegate respondsToSelector:@selector(didSelectedTemplateMessageCell:)]) {
        [self.delegate didSelectedTemplateMessageCell:templateDict];
    }
}

@end
